<template>
    <div class="mui-numbox" data-numbox-min="1" style="height: 25px;">
        <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
        <input id="test" class="mui-input-numbox" type="number" :value="value" @change="countChanged" ref="numbox" readonly/>
        <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
    </div>
</template>

<script>
import mui from "../libs/mui/js/mui.min";
export default {
    name: "CartNumbox",
    mounted() {
        mui(".mui-numbox").numbox();
    },
    methods: {
        countChanged() {
            console.log("count value", this.$refs.numbox.value);
            // 每当数量改变时，立即同步最新的数量到购物车的 store 中
            this.$store.commit("updateCartInfo", {
                id: this.id,
                count: parseInt(this.$refs.numbox.value)
            });
        }
    },

    props: ["value", "id"]
}
</script>

<style scoped>

</style>